package com.googlecode.recycled.lang.jse.lang;

import com.google.common.base.Strings;
import org.apache.commons.lang.StringUtils;

import javax.annotation.Nullable;

/**
 * Extension for Guava String utils (@see {@link com.google.common.base.Strings}).
 *
 * @author Henryk Konsek
 */
public class StringsExt {

    private StringsExt() {
    }

    /**
     * @deprecated Equivalent method has been added to the Commons-Lang3. It will
     *             be removed as soon as stable Lang3 is released.
     */
    @Deprecated
    public static boolean containsWhitespace(@Nullable String string) {
        if (Strings.isNullOrEmpty(string)) {
            return false;
        }
        for (int i = 0; i < string.length(); i++) {
            if (Character.isWhitespace(string.charAt(i))) {
                return true;
            }
        }
        return false;
    }

    public static String firstCharacters(@Nullable String string, int length) {
        if (StringUtils.isBlank(string)) {
            return StringUtils.EMPTY;
        }
        if (length >= string.length()) {
            return string;
        }
        return string.substring(0, length);
    }

}
